<?php
 require_once '../action/DB_MySQL.php';
 $mysql = new DB_MySQL;
 $mysql->connect('localhost', 'baocao', 'root', '');                                             
 $id=$_REQUEST[p];
 $hien=$_REQUEST[hien];
 $action=$_REQUEST[action];
 $depost=$_REQUEST[depost]; 

?>
<?php
  if(isset($_POST[sua])){
    $name=$_POST[name];
    $gia=$_POST[gia];
    $cate=$_POST[category];
    $number_art=$_POST[number_art];
    $chatlieu=$_POST[chatlieu];
    $mota=$_POST[mota];
    $ghichu=$_POST[ghichu];
    move_uploaded_file($_FILES['file']['tmp_name'],"../upload/".$_FILES['file']['name']);
                         $img=$_FILES['file']['name'];
    
     
    $sql="UPDATE sanpham  set name='{$name}', price='{$gia}', category='{$cate}',number_art='{$number_art}',chatlieu='{$chatlieu}',mota='{$mota}',ghichu='{$ghichu}' where id='{$id}'";         
    $mysql->query($sql);
?>
    <script type="text/javascript">
     window.location = "index.php?sanpham=true";
    </script> 
<?php
  }

?>


  <?php
   if(isset($hien)&& $hien=='true'){
    $mysql->query("UPDATE post set anhien='1' WHERE id={$id}");
   ?>
    <script type="text/javascript">
     window.location = "index.php?baiviet=true";
    </script>
    
  <?php }else if(isset($hien)&&$hien=='false'){
    $mysql->query("UPDATE post set anhien='0' WHERE id={$id}");
    
    ?>
    <script type="text/javascript">
     window.location = "index.php?baiviet=true";
    </script>
    
  <?php } else if(isset($action)&& $action=='delete'){
      $mysql->query("Delete from sanpham WHERE id={$id}");
      ?>
      <script type="text/javascript">
     window.location = "index.php?sanpham=true";
    </script>
      <?php
   }else if(isset($depost)&&$depost=='true'){
    $mysql->query("Delete from post WHERE id={$id}");
   ?>
    <script type="text/javascript">
     window.location = "index.php?baiviet=true";
    </script>
  <?php }
    else if(isset($hien)&&$hien=='sp1'){
        $sql= "UPDATE sanpham set kichhoat='1' WHERE id='{$id}'";
      $mysql->query($sql);   
    
    ?>
    <script type="text/javascript">
     window.location = "index.php?sanpham=true";
    </script>
    <?php
    } else if(isset($hien)&&$hien=='sp2'){
      $mysql->query("UPDATE sanpham set kichhoat='0' WHERE id='{$id}'");   
      ?>
      <script type="text/javascript">
     window.location = "index.php?sanpham=true";
    </script>
    <?php
      }else if(isset($_REQUEST[khuyenmai])&& $_REQUEST[khuyenmai]=='true'){
          $sql= "UPDATE sanpham set khuyenmai='1' WHERE id='{$id}'";
         $mysql->query($sql);   
      ?>
      <script type="text/javascript">
         window.location = "index.php?sanpham=true";
        </script>
      <?php 
      }else if(isset($_REQUEST[khuyenmai])&& $_REQUEST[khuyenmai]=='flase'){
          $sql= "UPDATE sanpham set khuyenmai='0' WHERE id='{$id}'";
         $mysql->query($sql);   
      ?>
  
      <script type="text/javascript">
         window.location = "index.php?sanpham=true";
        </script>
    <?php
	}else if(isset($_POST['ediphanloai'])){
	$name=$_POST['name'];
	$name_ct=$_POST['name'];
	echo $name_ct;
	$totalsp=$_POST['totalsp'];
	 $sql= "UPDATE  category set name='$name', totalproduct='$totalsp' WHERE id='{$id}'";
	 $sql_updatesp="UPDATE sanpham set category='$name_ct' "; 
         $mysql->query($sql); 
	     $mysql->query($sql_updatesp); 
	  
	?>
	<script type="text/javascript">
         window.location = "index.php?phanloai=true";
        </script>
		
  <?php
  } else if(isset($action)&& $action=='delete_pl'){
      $name=$_POST['category'];
      $mysql->query("Delete from category WHERE id={$id}");
	  $sql="DELETE FROM SANPHAM WHERE category='$name'";
	  $sql->query($sql);
      ?>
      <script type="text/javascript">
     window.location = "index.php?phanloai=true";
    </script>
      <?php
	  }
  ?>
  
  
  
  
  
  
  
  
  
  
  
  
